#include<iostream>
using namespace std;
int month[13] = { 0,31,28,31,30,31,30,31,31,30,31,30,31 };
bool Found(int n, int x)
{
	while (n)
	{
		if (n % 10 == x) {
			return true;
		}
		n /= 10;
	}
	return false;
}
int main()
{
	int y, m, x;
	scanf_s("%d%02d%d", &y, &m, &x);
	if (y % 400 == 0 || y % 4 == 0 && y % 100 != 0) {
		month[2] = 29;
	}
	int count = 0;
	for (int i = 1; i <= month[m]; i++)
	{
		if (Found(i, x)) {
			count++;
		}
	}
	cout << count + month[m] << endl;
	return 0;
}